﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace libLite.Forms
{
    public partial class addBook : Form
    {
        public CheckedListBox TagList;
        private OpenFileDialog otvoriSliku;

        public addBook()
        {
            InitializeComponent();
        }

        private void zarn_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            for (int i = 0; i < TagList.Items.Count; i++)
            {
                if (TagList.Items[i].ToString() == zarn.Items[e.Index].ToString())
                    TagList.SetItemCheckState(i, e.NewValue);
            }
        }

        public Bitmap Smanji(Bitmap b, int nWidth, int nHeight)
        {
            Bitmap result = new Bitmap(nWidth, nHeight);
            using (Graphics g = Graphics.FromImage((Image)result))
                g.DrawImage(b, 0, 0, nWidth, nHeight);
            return result;
        }

        private void groupBox4_Enter(object sender, EventArgs e)
        {

        }

        private void tagSearch_TextChanged(object sender, EventArgs e)
        {
            zarn.Items.Clear();
            for (int i = 0; i < TagList.Items.Count; i++)
            {
                if (TagList.Items[i].ToString().ToLower().Contains(addTag.Text.ToLower()))
                    zarn.Items.Add(TagList.Items[i], TagList.GetItemCheckState(i));

            }
        }

        private void addTag_Click(object sender, EventArgs e)
        {
          //  upit = new OdbcCommand("insert into zanrovi (naziv) values ('" + dodZarn.Text.Replace('\'', '`') + "')", KonWin.konekcija.ConObj);
          //  upit.ExecuteNonQuery();
            TagList.Items.Add(addTag.Text.Replace('\'', '`'), true);
            addTag.Text = "";
        }

        private void addBook_Load(object sender, EventArgs e)
        {
         /*   // Ubaci zarnove
            upit = new OdbcCommand("select naziv from zanrovi", KonWin.konekcija.ConObj);
            try
            {
                citac = upit.ExecuteReader();
                while (citac.Read())
                {
                    TagList.Items.Add(citac[0].ToString());
                    zarn.Items.Add(citac[0].ToString());
                }
            }
            catch (Exception ex) { MessageBox.Show("greska: " + ex); } */
        }

        private void button3_Click(object sender, EventArgs e)
        {
            autori.Items.Add(dAutor.Text);
        }

        private void slikaSaDiska_Click(object sender, EventArgs e)
        {
            otvoriSliku = new OpenFileDialog();
            if (this.otvoriSliku.ShowDialog() == DialogResult.OK)
            {
                slika.Image = (Image)Smanji((new Bitmap(otvoriSliku.FileName)), 143, 169);
            }
        }

        private void slikaIzClipboarda_Click(object sender, EventArgs e)
        {
            if (Clipboard.ContainsImage())
            {
                slika.Image = (Image)Smanji((Bitmap)Clipboard.GetImage(), 143, 169);
            }
            else
                MessageBox.Show("Clipboard ne sadrzi sliku!"); 
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            //LogOn.ConObj

            IDbCommand dbcmd = LogOn.ConObj.CreateCommand();
            dbcmd.CommandText = "insert into katalog () values (?,?,?,?)";
            IDataParameter param = dbcmd.CreateParameter();
            param.DbType = DbType.String;
            param.ParameterName = "shit";
            param.Value = "test";


            dbcmd.Prepare();
            dbcmd.ExecuteNonQuery();




            IDataReader reader = dbcmd.ExecuteReader();
        }

    }
}
